<template>
	<div class="box">
		<p class="top">
			<span @click="before">前一天</span>
			<datetime class='time' v-model="value" @on-change='change'></datetime> <span @click="next">后一天</span>
		</p>

		<div class="total">
			<p class="title">总分数</p>
			<p class="score">60分</p>
		</div>
		<p class="mes">评价详情</p>
		<ul class="detail">
			<li v-for="i in 3">
				<p>语文</p>
				<p>
					<img v-for="i in 4" src="../assets/record/star.png" alt="">
				</p>
			</li>
		</ul>


		<div class="return" @click="goBack">
			<img src="../assets/return.png" alt="">
		</div>
	</div>
</template>
<script>
	import {
		Group,
		Datetime
	} from 'vux'

	function timestamp2String(t) {
		var y = t.getFullYear()
		var m = t.getMonth() + 1
		if (m < 10) m = '0' + m
		var d = t.getDate()
		if (d < 10) d = '0' + d
		return `${y}-${m}-${d}`
	}

	function getPrevDay(val) {
		var t = new Date(val)
		t = new Date(t.getTime() - 1000 * 3600 * 24)
		return timestamp2String(t)
	}

	function getPrevYear() {
		var t = new Date();
		t = new Date(t.getTime() - 1000 * 3600 * 24 * 365)
		return timestamp2String(t)
	}

	function isPrevDay(val) {
		var t = new Date(val)
		t = new Date(t.getTime() - 1000 * 3600 * 24)
		t = timestamp2String(t)

		var v = getPrevYear()

		if (t < v) {
			return false
		} else {
			return true
		}

	}

	function isNextDay(val) {
		var t = getDefEndDate()
		if (val >= t) {
			return false
		} else {
			return true
		}
	}

	function getNextDay(val) {
		var t = new Date(val)
		t = new Date(t.getTime() + 1000 * 3600 * 24)
		return timestamp2String(t)
	}

	function getDefEndDate() {
		var t = new Date();
		return timestamp2String(t)
	}
	export default {
		components: {
			Datetime,
			Group
		},
		data() {
			return {
				value: '2018-10-13'
			}
		},
		created() {

		},
		mounted() {


		},
		methods: {
			goBack() {
				this.$router.back();
			},
			change() {
				console.log(this.value)
			},
			next() {
				if (isNextDay(this.value)) {
					this.value = getNextDay(this.value)
				}
			},
			before() {
				if (isPrevDay(this.value)) {
					this.value = getPrevDay(this.value)
				}
			}
		},


	}
</script>

<style lang="less" scoped="scoped">
	.box {
		.top {
			text-align: center;
			font-size: 14px;
			background: #FFF;
			height: 45px;
			line-height: 50px;

			.time {
				display: inline-block;
				width: 110px;
				height: 10px;
				font-weight: normal;
				line-height: 10px;
				margin: 0 auto;
				// text-align: left;
				background: #ECE9E6;
				border-radius: 10px;
				margin: 0 15px;
			}
		}


		.total {
			width: 90%;
			height: 90px;
			margin: 0 auto;
			background: #FFF;
			text-align: center;
			border-radius: 10px;
			margin-bottom: 10px;
			margin-top: 20px;

			.title {
				padding-top: 10px;
				font-size: 18px;
			}

			.score {
				font-size: 32px;
				color: rgb(24, 144, 255);
			}
		}

		.mes {
			text-align: center;
			color: #666;
			margin-top: -10px;
		}

		.dp-header .dp-item.dp-right {
			color: red;
		}

		.detail {
			list-style: none;
			width: 100%;
			height: 100%;

			li {
				background: #FFF;
				height: 40px;
				padding: 10px 15px;
				margin-bottom: 5px;
				position: relative;

				img {
					width: 18px;
					height: 18px;
				}
			}

			li:before {
				content: '';
				background: rgb(24, 144, 255);
				position: absolute;
				left: 5px;
				top: 15px;
				height: 16px;
				width: 3px;


			}

		}

		.return {
			width: 32px;
			height: 32px;
			position: absolute;
			top: 10px;
			left: 10px;

			img {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>
